$(function(){
    let form = layui.form
    form.verify({

        nickname: function (value) {
            if (value.length > 6) { 

                return '昵称太长了'
            }


        }
    })
    getUserInfo() 

    function getUserInfo() { 

        $.ajax({

            method: 'get',
            url: '/my/userinfo',
            success: function (res) { 
                if (res.status != 0) { 
                    layer.msg('获取失败')
                    return
                }
                console.log(res);
               form.val('formUserInfo',res.data)

            }
            
        })
    }

    $('#cz').on('click', function (e) { 
        e.preventDefault()
        getUserInfo() 


    })

    $('.layui-form').on('submit', function (e) { 

        e.preventDefault()
        $.ajax({
            method: 'post',
            url: '/my/userinfo',
            data: $(this).serialize(),
            success: function (res) { 
                if (res.status != 0) { 
                    return layer.msg('获取失败')
                }
                window.parent.getUserInfo()



            }
            
        })
    })
})